package com.woniuxy.job;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;

import com.woniuxy.pojo.Order;
import com.woniuxy.pojo.Order2;
import com.woniuxy.service.OrderService;
import com.woniuxy.service.impl.OrderServiceImp;
 
@Component
@EnableScheduling
public class FirstJob {
	@Resource
	OrderService os = new OrderServiceImp();
	public void task() {
		ArrayList<Order2> orders = new ArrayList<>();
		orders = os.all2();
		for(int i=0; i < orders.size(); i++){
			Order2 po = orders.get(i);
			int mm = (int) ((new Date().getTime() - po.getOstart().getTime())/1000);
			//超过三分钟自动取消
			if(mm >= 180 && po.getOpay().equals("线上支付") && po.getOstate().equals("未支付")){
				//修改订单状态
				os.changeStateByOid(po.getOid(), "已取消");
				//修改订单项状态
				os.changeDeleByOid(po.getOid(),1);
			}
		}
	}
 
	private SimpleDateFormat dateFormat() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
		return simpleDateFormat;
	}
}
